package com.labManage.controller;

import com.labManage.dao.LogDao;
import com.labManage.entity.Log;
import com.labManage.service.LogService;
import com.labManage.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/log")
public class LogController {

    @Autowired
    LogService logService;

    @Autowired
    LogDao logDao;

    @RequestMapping("/getLogList")
    @ResponseBody
    public ResultVo getLogList(Integer page, Integer limit, Log log){
        List<Log> logLists = logService.getLogList(page, limit, log);
        Long logNum = logDao.getLogNum();
        if(null!=logLists){
            return ResultVo.build(Math.toIntExact(logNum),0,"",logLists);
        }else {
            return ResultVo.build(201,"",null);
        }
    }

    @RequestMapping("/getRecentlyBorrowLog")
    @ResponseBody
    public ResultVo getRecentlyBorrowLog(){
        List<Log> logInfos = logService.getRecentlyBorrowLog();
        Long logNum = logDao.getLogNum();
        if(logInfos!=null){
            return ResultVo.build(Math.toIntExact(logNum),0,"",logInfos);
        }else {
            return ResultVo.build(201,"");
        }
    }
}
